//引入用来发送的请求方法
import{ request} from "../../request/index.js"
Page({
    data: {
        //轮播图
        swiperList:[],
        catesList:[],
        currentMonthIncome:0,
        currentMonthPay:0,
        memoCount:0,
    },
    onShow:function(options){
      // console.log(123);
      if(wx.getStorageSync('user').uid != undefined){
        this.getAmount();
        this.getMemoCount();
      }else{
        this.setData({
          currentMonthIncome:0,
          currentMonthPay:0,
          memoCount:0,
        })
      }
    },
    onLoad: function (options) {    
      // request({url:"http://localhost:8080/TheTimeSequence/Interlun"})
      // .then(request=>{
      //   this.setData({
      //     swiperList:request.data.message
      //   }) 
       
      // }) 
      this.getSwiperList();
      this.getCateList();
      if(wx.getStorageSync('user').uid != undefined){
        this.getAmount();
        this.getMemoCount();
      }
    }, 
  //获取轮播图 
    getSwiperList(){ 
      request({url: "http://localhost:8080/TheTimeSequence/Interlun"}) 
      .then(result => {
        this.setData({
          swiperList: result.data.message
        })  
      })
    },
     // 获取 分类导航数据
  getCateList(){
    request({ url: "https://api-hmugo-web.itheima.net/api/public/v1/home/catitems" })
    .then(result => {
      this.setData({
        catesList: result.data.message
      }) 
    })
  },
  //获取本月收入和支出金额
  getAmount(){
    wx.request({
      url: 'http://localhost:8080/TheTimeSequence/BooksServlet?opr=currentMonthAmount',
      data: {
        uid:wx.getStorageSync('user').uid
      },
      success: (e) => {
        // console.log(e.data);
        this.setData({
          currentMonthIncome:e.data.income,
          currentMonthPay:e.data.pay
        })
      } 
    })
  },
  //获取总备忘录条数
  getMemoCount(){
    wx.request({
      url: 'http://localhost:8080/TheTimeSequence/MemoServlet?opr=count',
      data: {
        uid:wx.getStorageSync('user').uid
      },
      success: (e) => {
        // console.log(e.data);
        this.setData({
          memoCount:e.data
        })
      } 
    })
  }
});
  
